<template>
	<view class="con-box">
		<u-navbar title="" height="120upx">
			<view class="u-nav-slot" slot="left">
				<view @tap="back" class="icon-left">
					<u-icon name="arrow-left" color="#000" size="26"></u-icon>
				</view>
			</view>
			<view class="u-nav-slot logoBox" slot="center">
				<view class="navBox">注销账号</view>
			</view>
			<view class="u-nav-slot" slot="right">
				<view class="icon-right">
				</view>
			</view>
		</u-navbar>

		<view class="form">
			<view class="step1">
				<text>当前账号</text>
				<view>{{uerInfo.mobile | setPhone}}</view>
				<text>请确认您的账号中是否存在操作中的产品</text>
				<text>如待付款，操作完成后可注销账户</text>
			</view>

		</view>
		<view class="submit-bottom">
			<view class="submit-btn" @tap="cancellation">注销账号</view>
		</view>

		<u-popup :show="show" mode="center" @close="show = false" :round="10">
			<view class="modeBox">
				<view class="title">确认注销</view>
				<view class="txt">提交账户注销申请90天内，您仍可登录该账号，若超过90天未登录，您的账户将被注销且不可恢复，请谨慎操作。</view>
				<view class="foot">
					<view class="bottom_btn">
						<view class="btn_item line" @tap="show = false">再想想</view>
						<view class="btn_item" @tap="confirmLogout">确认注销</view>
					</view>
				</view>
			</view>
		</u-popup>

		<u-toast ref="uToast"></u-toast>
		<mix-loading ref="min_loading"></mix-loading>
	</view>
</template>

<script>
	import {
		logout,
		logoutAccount
	} from '@/api/login.js'
	import {
		mapState
	} from 'vuex';
	export default {
		data() {
			return {
				show: false,
				form: {
					viewCode: "",
					verifyCode: "",
					uid: "",
					mobile: ""
				},
				codeUid: "",
				codeSrc: ""
			}
		},
		onShow() {
			this.getImgCode();
		},
		methods: {
			confirmLogout() {
				logoutAccount().then(res => {
					if (res.data.success) {
						this.$refs.uToast.show({
							type: 'success',
							message: "注销成功！"
						});
						this.outLogin();
					} else {
						this.$u.toast(res.data.msg);
					}
					this.show = false;
				})
			},
			cancellation() {
				this.show = true;
			},
			// 退出登录
			outLogin() {
				logout().then(res => {
					if (res.data.success) {
						this.$store.dispatch("OutLogin");
						uni.reLaunch({
							url: "/pages/login/login"
						});
					}
				})
			},
			getImgCode() { //获取图形验证码
				this.codeUid = new Date().getTime();
				this.codeSrc = `${this.baseApi}/code/loginCode?uid=${this.codeUid}`;
			},
			back() {
				let canNavBack = getCurrentPages();
				if (canNavBack && canNavBack.length > 1) {
					uni.navigateBack({
						delta: 1
					});
				} else {
					history.back();
				}
			},
		},
		computed: {
			...mapState(["hasLogin", "uerInfo"]),
		},
		filters: {
			setPhone(data) {
				let phone = "";
				if (data) {
					phone = data.substr(0, 3) + "****" + data.substr(7, 10);
				}
				return phone;
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		width: 100%;
		height: 100%;
	}

	.con-box {
		padding-top: 140upx;
		height: 100%;

		.modeBox {
			// padding: 0 40upx;
			// padding-bottom: 38upx;
			width: 640upx;
			font-size: 30upx;

			.foot {
				display: flex;
				align-items: center;
				justify-content: space-between;
				// font-size: 26upx;
				// color: #C09B3A;
				// padding: 0 76upx;
				padding-top: 68upx;
				font-weight: bold;

				.bottom_btn {
					width: 100%;
					font-size: 14px;
					font-family: PingFang SC;
					font-weight: 500;
					color: #C09B3A;
					display: flex;
					align-items: center;
					justify-content: center;
					box-shadow: 0upx -1upx 0px 0px #BCBCBC;
					
					.btn_item {
						flex: 1;
						display: flex;
						align-items: center;
						justify-content: center;
						height: 88upx;
					}

					.line {
						box-shadow: 1upx 0px 0px 0px #BCBCBC;
					}
				}

			}

			.txt {
				text-align: justify;
				line-height: 48upx;
				color: #666;
				padding: 0 40upx;
			}

			.title {
				padding: 0 40upx;
				color: #333;
				text-align: center;
				padding-top: 66upx;
				padding-bottom: 20upx;
				font-weight: 800;
			}
		}

		.form {
			height: 100%;
			background-color: #fff;

			.step1 {
				padding-top: 160upx;
				text-align: center;

				text {
					display: block;
					font-size: 24upx;
					color: #666;
				}

				text:last-child {
					margin-top: 16upx;
				}

				view {
					margin: 30upx 0;
					margin-bottom: 86upx;
					font-size: 60upx;
					color: #333;
				}

				image {
					width: 160upx;
					margin-bottom: 30upx;
				}
			}
		}

		.submit-bottom {
			width: 100%;
			position: fixed;
			left: 0;
			bottom: 0;
			padding: 0 58upx;
			padding-bottom: 100upx;

			.submit-btn {
				width: 100%;
				height: 96upx;
				background: #CEA539;
				border-radius: 10upx;
				font-size: 32upx;
				font-weight: bold;
				color: #FFFFFF;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}

		.logoBox {
			width: 100%;
			height: 100%;

			.navBox {
				height: 120upx;
				display: flex;
				align-items: center;
				justify-content: center;
				color: #000;
				box-shadow: 0px 0px 1px 0px rgba(51, 51, 51, 0.5000);
				font-size: 32upx;
				font-family: PingFang SC;
				font-weight: bold;
			}
		}
	}
</style>
